<template>

  <van-form @submit="onSubmit">
    <van-cell-group inset>
      <van-field
        v-model="user.store"
        placeholder="店铺名称"
        name="store"
        required
        :rules="[{ required: true, message: '请填写店铺名称' }]"
        label="店铺名称"
      />
      <van-field
        v-model="user.mobile"
        name="mobile"
        label="商家手机号"
        placeholder="商家手机号"
      />
      <van-field
        v-model="user.qq"
        required
        label="商家QQ"
        name="qq"
        placeholder="商家QQ"
        :rules="[{ required: true, message: '请填写商家QQ' }]"
      />
      <van-field
        v-model="user.from"
        required
        label="放单平台"
        name="from"
        placeholder="放单平台"
        :rules="[{ required: true, message: '请填写放单平台' }]"
      />
      <van-field label="截图上传" required
        name="file"
        :rules="[{ required: true, message: '请上传截图' }]">
        <template #input>
          <van-uploader :after-read="afterRead" v-model="files" :readonly="true" :max-count="1"/>
        </template>
      </van-field>
    </van-cell-group>
    <div style="margin: 20px 40px">
      <van-button block type="primary" native-type="submit" class="aui-bg-red">
        提交申请1.00元奖励金
      </van-button>
    </div>
    <div class="aui-text-6 aui-ftn12 aui-padded-15" style="line-height: 1.8;">
      <span class="aui-text-red">亲爱的用户</span>您好:极客试用正在收集好的商家信息,可以按照上面的表格如实填写,将给予<span class="aui-text-red">1.00</span>元现金奖励,返还至您的试用网帐户!
    </div>
  </van-form>
</template>

<script>
  import { readSync } from 'fs';
import User from '../../service/user.js'
  export default {
    data () {
      return {
        user: {
          uid: '',
          store: '',
          image: '',
          mobile: '',
          qq: '',
          from: ''
        },
        files: []
      }
    },
    mounted() {
      this.user.uid = this.$store.state.uid;
    
    },
      methods: {
        afterRead(file) {
          console.log(file)
          this.user.image = file.file;
        },
        onSubmit () {
          let param = new FormData() // 创建form对象
          for (var i in this.user) {
            param.append(i, this.user[i]) // 添加form表单中其他数据
          }
          User.fnAddRecommend(param).then(res => {
            if (res) {
              this.utils.fnMsg(res.msg);
              if (res.status) {
                setTimeout(() => {
                  this.utils.fnOpenCommon(this, {name: 'recommend_list', query: {title: '推荐有奖记录'}})
                }, 500)
                
              }
            }
          })
        }
      }
    }

</script>

<style lang="scss">
    div.recommend {
      li {
        height: 50px;
        line-height: 50px;
        .input {
          border: 0;
          height: 50px;
          line-height: 50px;
          background-color: transparent!important;
        }
        .gender {
          -webkit-justify-content: flex-end;
              -ms-flex-pack: end;
                  justify-content: flex-end;
        }
      }
      div.submit_btn {
        height: 50px;
        line-height: 50px;
      }
    }
</style>
